<?php
/**
 * Created by PhpStorm.
 * User: kcross
 * Date: 20-6-25
 * Time: 下午6:00
 * @property int $id
 * @property string name
 * @property int $uid
 */
namespace  App\Models;

class Group extends \Illuminate\Database\Eloquent\Model implements IReadable
{
    protected $table = "group";

    protected $guarded = [];

    public static function createGroup($name, $uid)
    {
        $model = new self();
        $model->uid = $uid;
        $model->name = $name;
        $model->save();
    }

    public function attributeLabels()
    {
        return [
            'name' => '群名称'
        ];
    }



    public static function getByUid($uid = null)
    {
        if (is_null($uid)) {
            $uid = \Encore\Admin\Facades\Admin::guard()->id();
        }
        $data = self::query()->where("uid", $uid)->get()->toArray();
        $res = [];
        foreach ($data as $item) {
           $res[$item['wxid']] = $item['name'];
        }

        return $res;
    }

}